// https : // iai.sh.cn/problem/429
#include <bits/stdc++.h>
using namespace std;
struct Banji {
  int id;

  double a;
  double b;
  double c;
  double d;
  int sum;
};

Banji bj[100005];
int main() {
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;

    int a = 0, b = 0, c = 0, d = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == 'A') {
        a++;
      } else if (s[j] == 'B') {
        b++;
      } else if (s[j] == 'C') {
        c++;
      } else if (s[j] == 'D') {
        d++;
      }
    }
    int total = s.size();
    bj[i].id = i;
    bj[i].a = a * 1.0 / total;
    bj[i].b = b * 1.0 / total;
    bj[i].c = c * 1.0 / total;
    bj[i].d = d * 1.0 / total;
    bj[i].sum = total;
  }

  sort(bj + 1, bj + n + 1, [](Banji x, Banji y) {
    if (x.a != y.a) {
      return x.a > y.a;
    } else if (x.b != y.b) {
      return x.b > y.b;
    } else if (x.c != y.c) {
      return x.c > y.c;
    } else if (x.sum != y.sum) {
      return x.sum > y.sum;
    } else {
      return x.id < y.id;
    }
  });

  for (int i = 1; i <= n; i++) {
    cout << bj[i].id << " ";
  }
  return 0;
}